<?php

#读者墙插件
RegisterPlugin("Regtas","ActivePlugin_Regtas");

function ActivePlugin_Regtas() {
	global $zbp;
	Add_Filter_Plugin('Filter_Plugin_Index_Begin','Regtas_Main');
	if(!$zbp->Config('Regtas')->dz_gs)$zbp->Config('Regtas')->dz_gs=50;
}

$table['comment']='%pre%comment';

function InstallPlugin_Regtas(){
	global $zbp;
		if(!$zbp->Config('Regtas')->title_text){
		$zbp->Config('Regtas')->title_text='读者墙';
		$zbp->Config('Regtas')->dz_gs='50';
		$zbp->SaveConfig('Regtas');
	}
}

function Regtas_Main(){
	global $zbp;

	if(isset($_GET['ReaderWall'])){
	Regtas_Page();
		die();
	}
	
}


function Regtas_Page(){

	global $zbp;
	$zbp->header .='<link rel="stylesheet" href="'.$zbp->host.'zb_users/plugin/Regtas/style.css" type="text/css" />' . "\r\n";
	$article = new Post;
	$article->Title=$zbp->Config('Regtas')->title_text;
	
	$article->IsLock=true;
	$article->Type=ZC_POST_TYPE_PAGE;
	$article->Content .='<p style="text-align: center;">'.$zbp->Config('Regtas')->readme_text.'</p>';
	$article->Content .=TCWL_Readers();;
    $mt=microtime();
    $s= '';
	$article->Content .=$s;	
	$zbp->template->SetTags('title',$article->Title);
	$zbp->template->SetTags('article',$article);
	$zbp->template->SetTemplate($article->Template);
	$zbp->template->SetTags('comments',array());
    foreach ($GLOBALS['Filter_Plugin_ViewPost_Template'] as $fpname => &$fpsignal) {
        $fpreturn=$fpname($zbp->template);
    }
	$zbp->template->Display();
}

function TCWL_Readers() {
 global $zbp;
$date =$zbp->Config('Regtas')->dz_ts;
$dzgs =$zbp->Config('Regtas')->dz_gs;
$b =strtotime("-".$date."day");
$e = mktime(0,0,0,date('m'),date('d')+1,date('Y'));
$x =$zbp->Config('Regtas')->open_reg;
$rs=$zbp->Config('Regtas')->dz_gs;
$sql = $zbp->db->sql->Select(
$zbp->table['Comment'],
array('COUNT(comm_ID) AS cnt, comm_Name, comm_HomePage , comm_Email'),
array(
array('<>', 'comm_Email', $x),
array('<>', 'comm_Name', '访客'),
array('<>', 'comm_Name', 'admin'),
array('BETWEEN', 'comm_PostTime', $b, $e),
array('CUSTOM', '1=1 GROUP BY comm_HomePage')
),
array('cnt' => 'DESC'),
$dzgs,
null
);
$array=$zbp->db->Query($sql);
$s="<ul class='readers-list'>";
$s .="\r\n";
	foreach ($array as $comment) {
		$r="rel='external nofollow'";
		$s .= '<li><a href="'.$comment['comm_HomePage'] . '" ' . $r . ' title="' . $comment['comm_Name'] . '(赐教' . $comment['cnt'] . '次)" target="_blank"><img src="http://cn.gravatar.com/avatar/' .md5(strtolower($comment['comm_Email'])).' &r=X&s=80" alt="avatar" class="avatar avatar-36 photo" height="36" width="36" /><em>'.$comment['comm_Name'] .'</em><strong>+'.$comment['cnt'].'</strong></a></li>';
		$s .="\r\n";
	}
	
$s .="</ul>";
$s .="\r\n";
return $s;
}


?>